package com.meida.student.app.user.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.mybatis.interceptor.GetInterceptor;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.bus.client.entity.BusOrder;
import com.meida.module.bus.client.entity.BusSubject;
import com.meida.module.bus.provider.service.BusOrderService;
import com.meida.module.bus.provider.service.BusSubjectService;
import com.meida.module.bus.provider.utils.MyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("BusOrderSimpleDetailHandler")
public class BusOrderSimpleDetailHandler implements GetInterceptor {

    @Autowired
    private BusSubjectService busSubjectService;

    @Autowired
    private BusOrderService busOrderService;

    @Override
    public void prepare(CriteriaQuery cq, EntityMap entityMap) {
        cq.clear();
        cq.select(BusOrder.class, "orderId", "orderNo", "orderType", "orderState", "subjectId", "subjectIds", "orderDescribe", "payableAmount", "createTime");
        cq.select(BusSubject.class, "subjectTitle");
        cq.eq(BusOrder.class, "orderId");
        cq.createJoin(BusSubject.class).setMainField("subjectId").setJoinField("subjectId");

    }

    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        //处理专业,专业标签
        String subjectIds = map.get("subjectIds");
        Integer orderType = map.getInt("orderType");
        List<String> subjectTitles = busSubjectService.selectSubjectTitles(subjectIds);
        map.put("subjectTitles", subjectTitles);
        String orderTypeDesc = busOrderService.getOrderTypeDesc(orderType);
        map.put("orderTypeDesc", orderTypeDesc);
    }


}
